from sanic import Sanic
from sanic_base_ext import BaseExtension

class CustomExtension(BaseExtension):
    extension_name = app_attribute = 'custom'   # ctx后面的参数需要
    
    def hello(self, user):
        print("Hello, {}!".format(user))

app = Sanic(__name__)
CustomExtension(app)
app.ctx.custom.hello('world')